package org.example.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.example.common.R;
import org.example.entity.Post;
import org.example.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/post")
public class PostController {
    @Autowired
private PostService postService;
    @GetMapping("/page")
    public R<List<Post>> page() {
        //构造查询条件
         LambdaQueryWrapper<Post> queryWrapper = new LambdaQueryWrapper();
         List<Post> list = postService.list(queryWrapper);
        // 按照createTime字段升序排序，确保先创建的在前面展示
        queryWrapper.orderByAsc(Post::getCreateTime);
        return R.success(list);
    }
}
